﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Luminji.Core.Json;

namespace Luminji.Core.UnitTest.Json
{
    [TestClass]
    public class JsonHelperTest
    {
        [TestMethod]
        public void TestMethodGetJson()
        {
            var papers = new List<Paper>()
                             {
                                 new Paper() {Name = "p1"},
                                 new Paper() {Name = "p2"},
                                 new Paper() {Name = "p3"}
                             };
            var student = new Student() {Name = "luminji", Age = 22, Papers = papers};
            string actual = JsonHelper.ToJson<Student>(student);
            string expected =
                "{\"Age\":22,\"Name\":\"luminji\",\"Papers\":[{\"Name\":\"p1\"},{\"Name\":\"p2\"},{\"Name\":\"p3\"}]}";
            Assert.AreEqual(expected,actual);
        }


        [TestMethod]
        public void TestMethodGetObject()
        {
            string str = "{\"Age\":22,\"Name\":\"luminji\",\"Papers\":[{\"Name\":\"p1\"},{\"Name\":\"p2\"},{\"Name\":\"p3\"}]}";
            Student student = JsonHelper.ToModel<Student>(str);
            Assert.IsNotNull(student);
        }

    }

    public class Student
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public IList<Paper> Papers { get; set; }
    }

    public class Paper
    {
        public string Name { get; set; }
    }
}
